<!-- 我的 -->
<template>
  <view class="me">
    <view class="me_head">
      <view class="head_title">王丽丽</view>
      <view class="head_info">
        <!-- 我的办理 -->
        <view class="info">
          <view class="p1">
            <image
              style="width: 15px; height: 15px; background: #fff"
              src="../../static/index/wdebanli.png"
            />
            <view
              class="txt"
              style="marginleft: 5px"
            >学号：20220523</view>
          </view>
        </view>
        <view class="info">
          <view class="p1">
            <image
              style="width: 15px; height: 15px; background: #fff"
              src="../../static/index/wdebanli.png"
            />
            <view
              class="txt"
              style="marginleft: 5px"
            >院系：城市规划系</view>
          </view>
        </view>
        <view class="info">
          <view class="p1">
            <image
              style="width: 15px; height: 15px; background: #fff"
              src="../../static/index/wdebanli.png"
            />
            <view
              class="txt"
              style="marginleft: 5px"
            >专业：材料</view>
          </view>
        </view>
      </view>
    </view>

    <!-- 我的办理 -->
    <view
      class="options"
      @tap="options3"
    >
      <view class="p1">
        <image
          style="width: 15px; height: 15px; background: #fff"
          src="../../static/index/wdebanli.png"
        />
        <view
          class="txt"
          style="marginleft: 5px"
        >我的办理</view>
      </view>
      <nut-icon
        name="right"
        color="#dddddd"
      ></nut-icon>
    </view>
    <!-- 我的入学信息 -->
    <view
      class="options"
      @tap="options1"
    >
      <view class="p1">
        <image
          style="width: 15px; height: 15px; background: #fff"
          src="../../static/index/woderuxue.png"
        />
        <view
          class="txt"
          style="marginleft: 5px"
        >离院记录</view>
      </view>
      <nut-icon
        name="right"
        color="#dddddd"
    ></nut-icon>
    </view>

    <view
      class="outLogin"
      @tap="tuichu"
    >退出登录</view>
  </view>
</template>

<script>
import "./my.less";
import Taro, { useRouter, getCurrentInstance } from "@tarojs/taro";
import QRCode from "qrcode"; //需要的页面引入

export default {
  data() {
    return {
      //请求回来的数据
      qrCodeUrl: "",
      myData: {},
      value1: "",
      ew: false,
      zuidashu: {},
      //办理状态
      banlizhuangtai: {},
      fangyi: {},
    };
  },

  onShow(options) {
    this.GetMy();
    this.getbanlizhuangtai();
    this.panduan();
  },
  methods: {
    //  生成二维码
    qrcode(code) {
      console.log("qrcode");
      QRCode.toDataURL(code, { backgroundColor: null, margin: 2 }).then(
        (url) => {
          this.qrCodeUrl = url;
        }
      );
    },
    //判断防疫申请有没有填写完成
    panduan() {
      if (this.fangyi["apply_admission_id.status"] == "pass") {
        // console.log("999999")
        this.ew = true;
      } else {
        this.ew = false;
      }
    },
    //入学防疫申请查询
    async getfangyi() {
      let that = this;
      const userInfo = Taro.getStorageSync("userInfo");
      that.flora.dash.dataApi
        .search({
          vars: {
            fields: [
              "id",
              "code",
              "name",
              "class",
              "phone",
              "apply_admission_id.id",
              "apply_admission_id.status",
              "apply_admission_id.registration_time",
              "apply_admission_id.time",
              "apply_admission_id.health_code_id.id",
              "apply_admission_id.health_code_id.download_url",
              "apply_admission_id.itinerary_code_id.id",
              "apply_admission_id.itinerary_code_id.download_url",
              "apply_admission_id.travel_date",
              "apply_admission_id.province_text",
              "apply_admission_id.city_text",
              "apply_admission_id.district",
              "apply_admission_id.travel_mode",
              "apply_admission_id.shift",
              "apply_admission_id.vaccination",
              "apply_admission_id.vaccination_manu",
              "apply_admission_id.vaccination_number",
              "apply_admission_id.is_strengthen",
              "apply_admission_id.vaccination_img_ids.id",
              "apply_admission_id.vaccination_img_ids.download_url",
            ],
            model: "FreshStudent",
            condition: {
              logic_operator: "&",
              children: [
                {
                  leaf: {
                    field: "code",
                    comparator: "=",
                    value: userInfo.code,
                  },
                },
              ],
            },
            limit: 10,
            offset: 0,
          },
          cacheMode: "no-cache",
        })
        .then((r) => {
          console.log("------------", r);
          const str = r.result.items[0].data;
          console.log(str);
          this.fangyi = str;
          this.panduan();
        });
    },

    //
    async GetMy() {
      let that = this;
      const userInfo = Taro.getStorageSync("userInfo");
      that.qrcode(userInfo.code);
      that.flora.dash.dataApi
        .search({
          vars: {
            fields: [
              "id",
              "code",
              "name",
              "name_pin_yin",
              "class",
              "phone",
              "email",
              "bank_province_text",
              "bank_city_text",
              "bank_name_text",
              "bank_text",
              "bank_card_code",
              "cultivation_type",
              "department_id.name",
              "major_id.name",
              "research_direction_id.name",
              "id_card",
              "sex",
              "political_status_id.name",
              "ethnic_group_id.name",
              "shirt_size",
              "face_img_id.download_url",
              "face_img_id.id",
              "id_codef_id.download_url",
              "id_codef_id.id",
              "id_codez_id.download_url",
              "id_codez_id.id",
              "belief",
              "origin_land",
              "status",
            ],
            model: "FreshStudent",
            condition: {
              logic_operator: "&",
              children: [
                {
                  leaf: {
                    field: "code",
                    comparator: "=",
                    value: userInfo.code,
                  },
                },
              ],
            },
            limit: 10,
            offset: 0,
          },
          cacheMode: "no-cache",
        })
        .then((r) => {
          console.log("------------", r);
          //使用数据源
          const str = r.result.items[0].data;
          //打印获取的数据源
          console.log(str);
          this.myData = str;
          //  msg=str[0]
        });
    },
    //查询最大数
    async getzuidashu() {
      let that = this;
      const userInfo = Taro.getStorageSync("userInfo");
      that.flora.dash.dataApi
        .search({
          vars: {
            // fields: ['id', 'code', 'name', 'major','department','researchDirection','status'],
            fields: ["code", "zdtjs"],
            model: "FreshStudent",
            condition: {
              logic_operator: "&",
              children: [
                {
                  leaf: {
                    field: "code",
                    comparator: "=",
                    value: userInfo.code,
                  },
                },
              ],
            },
            limit: 10,
            offset: 0,
          },
          cacheMode: "no-cache",
        })
        .then((r) => {
          console.log("------------", r); //使用数据源
          const str = r.result.items[0].data; //打印获取的数据源
          console.log(str);
          this.zuidashu = str;
          console.log("*****");
          this.panduan(); //  msg=str[0]
        });
    },
    //查询办理状态
    async getbanlizhuangtai() {
      let that = this;
      const userInfo = Taro.getStorageSync("userInfo");
      that.flora.dash.dataApi
        .search({
          vars: {
            // 入校状态
            fields: [
              "code",
              "apply_admission_status",
              "apply_admission_id.write_date",
              "qualification_status",
              "qualification_id.write_date",
              "tuition_status",
              "tuition_id.write_date",
              "loan_status",
              "loan_id.write_date",
              "card_collection_status",
              "card_collection_id.write_date",
              "organization_transfer_status",
              "organization_transfer_id.write_date",
              "party_information_status",
              "party_information_id.write_date",
              "account_migration_status",
              "account_migration_id.write_date",
              "college_shirt_collection_status",
              "college_shirt_collection_id.write_date",
              "key_status",
              "key_id.write_date",
            ],
            model: "FreshStudent",
            condition: {
              logic_operator: "&",
              children: [
                {
                  leaf: {
                    field: "code",
                    comparator: "=",
                    value: userInfo.code, //
                  },
                },
              ],
            },
            limit: 10,
            offset: 0,
          },
          cacheMode: "no-cache",
        })
        .then((r) => {
          const str = r.result.items[0].data;
          console.log(str);
          this.banlizhuangtai = str;
          this.getzuidashu();
          this.getfangyi();
        });
    },
    // 跳转
    options1() {
      Taro.navigateTo({
        url: "/pages/myForm/liyuanjilu",
      });
    },
    options2() {
      Taro.navigateTo({
        url: "/pages/myForm/end9Form",
      });
    },
    options3() {
      Taro.navigateTo({
        url: "/pages/mytask/myHandle/myHandle",
      });
    },
    //退出登录
    tuichu() {
      const userInfo = Taro.getStorageSync("userInfo");
      var id = userInfo?.["wechat_id.id"];
      let that = this;
      that.flora.dash.dataApi
        .save({
          vars: {
            model: "FreshWechat",
            values: {
              id: id,
              open_id: "",
            },
          },
        })
        .then((res) => {
          console.log("-goOut=>", res);
          if (res.result.status === "ok") {
            Taro.clearStorageSync();
            Taro.clearStorage();
            // Taro.showToast({
            //     title: '退出成功',
            //     icon: 'success',
            // })
            // Taro.showToast('退出成功', 'success')
            Taro.redirectTo({ url: "/pages/login/login" }); //退出成功页面跳转
            return;
          }
          showToast("退出失败请重试~");
        });
    },
  },
  created() {
    this.getbanlizhuangtai();
  },
  mounted() {
    // this.panduan()
  },
};
</script>

